import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[][] array = new int[3][];
        //java当中的数组可以省略列，但是不能省略行

    }
    public static void reverse(int[] array) {
        int left = 0;
        int right = array.length - 1;
        while(left < right) {
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            right--;
            left++;
        }
    }
    //数组逆序:
    public static void main7(String[] args) {
        int[] array = {1,2,5,7};
        reverse(array);
        System.out.println(Arrays.toString(array));
    }
    //冒泡排序
    public static void bubbleSort(int[] array) {
        //只需要array.length -1趟
        for(int i = 0;i < array.length - 1; i++) {
            int count = 0;
            //每完成一趟，比较次数就减少一次
            for(int j = 0; j < array.length - 1 - i; j++) {
                //此时是排成升序
                if(array[j] > array[j + 1]) {
                    int tmp = array[j + 1];
                    array[j + 1] = array[j];
                    array[j] = tmp;
                    count++;
                }
            }
            if(count == 0); {
                break;//没完成一趟检测是否有进行交换排序，如果没有就表明这个数组是有序的，不需要进行排序，直接跳出循环
            }

        }
    }


    public static void main6(String[] args) {
        int[] array = {1,2,5,7};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));

    }
    //数组拷贝
    public static void main5(String[] args) {
        int[] array = {1,2,3,5,6,7,8};
        int[] newArray = Arrays.copyOf(array,array.length);//拷贝整个array数组
        System.out.println(Arrays.toString(array));
        int[] newArrays = Arrays.copyOfRange(array,2,5);//范围在[2,5)的下标的元素
        System.out.println(Arrays.toString(newArrays));
    }
    //数组转为字符串
    public static void main4(String[] args) {
        int[] array = {1,2,3,4,5};
        String array1 = Arrays.toString(array);
        System.out.println(array1);
    }
    public static void func(int[] array) {
        array = new int[] {1,2,6,4};
    }
    public static void main3(String[] args) {

        int[] array = {1,2,3,4,5,6,7};
        System.out.println("前：" + Arrays.toString(array));
        func(array);
        System.out.println("后" + Arrays.toString(array));
    }
    public static void main2(String[] args) {
        int[] array;
        array = new int[5];
        int[] array1;
        array1 = new int[]{1,2,3,4,5};
        for (int a:array1) {
            System.out.println(a);
        }
        /*int[] array = new int[10];//动态初始化
        int[] array1 = {1,2,3,4,5,6,7,8};*/
    }
    public static void main1(String[] args) {
        int n = 5;
        int ret = factor(n);
        System.out.println("ret = " + ret);
    }
    public static int factor(int n) {
        System.out.println("函数开始，n= " + n);
        if(n == 1) {
            System.out.println("函数结束, n = 1 ret = 1");
            return 1;
        }
        int ret = n * factor(n -1);
        System.out.println("函数结束， n = " + n + "ret = " + ret);
        return ret;
    }
}


